/**
 * @param {any[]} arr
 * @param {number} depth
 * @return {any[]}
 */
var flat = function _flatFunc(arr, n) {
    if (n == 0) return arr;
    let result = [];
    for (let i=0; i < arr.length; i++) {
        if (Array.isArray(arr[i])) {
            result.push(..._flatFunc(arr[i], n-1));
        } else {
            result.push(arr[i]);
        }
    }
    return result;
};
